package com.wtwd.device.service.impl;

import com.wtwd.device.dao.AppFrequencyMapper;
import com.wtwd.device.dao.SetHeartRateWarningMapper;
import com.wtwd.device.model.entity.Frequency;
import com.wtwd.device.model.entity.SetHeartRateWarning;
import com.wtwd.device.model.vo.FrequencyAndValueVo;
import com.wtwd.device.service.SetHeartRateWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SetHeartRateWarningServiceImpl implements SetHeartRateWarningService {
    private Integer type = 1;
    @Autowired
    private SetHeartRateWarningMapper setHeartRateWarningMapper;

    @Autowired
    private AppFrequencyMapper appFrequencyMapper;
    @Override
    public FrequencyAndValueVo getHeartRateWarningByDeviceId(Long deviceId) {
        FrequencyAndValueVo frequencyAndValueVo = new FrequencyAndValueVo();
        Frequency frequency = appFrequencyMapper.selectFrequencyByDeviceId(type, deviceId);
        if(frequency != null){
            frequencyAndValueVo.setType(frequency.getType());
            frequencyAndValueVo.setValue(frequency.getValue());
        }
        SetHeartRateWarning heartRateWarningByDeviceId = setHeartRateWarningMapper.getHeartRateWarningByDeviceId(deviceId);
        if(heartRateWarningByDeviceId != null){
            frequencyAndValueVo.setMaxValue(heartRateWarningByDeviceId.getMaxHeartRate());
            frequencyAndValueVo.setMinValue(heartRateWarningByDeviceId.getMinHeartRate());
        }
        return frequencyAndValueVo;
    }
}
